#include <stdio.h>
#include <stdlib.h>
#include "util.h"
#include "absyn.h"
#include "errormsg.h"
#include "parse.h"
#include "prabsyn.h"

#include "env.h"
#include "semant.h"

int main(int argc, char **argv) {
  if(argc != 2) {fprintf(stderr, "usage: a.out input_filename\n"); exit(1); }
//if (argc!=3) {fprintf(stderr,"usage: a.out filename out\n"); exit(1);}
// abstract syntax tree

  A_exp res = parse(argv[1]);
  
  printf("\n=== printing syntax tree ===\n");
  //FILE* out = fopen(argv[2], "w");
  FILE* out = stdout;
  pr_exp(out, res, 4);
  printf("\n============================\n");
  
  
  // IR tree
  printf("\n===== printing IR tree =====\n");
  SEM_transProg(res);
  printf("\n============================\n");


/*
while(1){
  char buf[255] = { 0 };
  printf("please input the file dir: ");
  scanf("%s", buf);
  //A_exp res = parse(argv[1]);
  if(strcmp(buf, "quit") == 0){
    break;
  }else{
    A_exp res = parse(buf);
    //FILE* out = fopen(argv[2], "w");
    //pr_exp(out, res, 4);
    // IR tree
    SEM_transProg(res);
  }
}
  system("pause");
*/
  return 0;
}
